package com.sunlands.zlcx.usercenter.service.status.common;

import com.sunlands.zlcx.usercenter.domain.UsersTargetRelationDO;
import com.sunlands.zlcx.usercenter.exception.CheckRunException;
import com.sunlands.zlcx.usercenter.util.AssertUtil;
import com.sunlands.zlcx.usercenter.vo.UsersStudyInfoVO;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.concurrent.ExecutionException;

import static com.sunlands.zlcx.usercenter.vo.CommonResultMessage.USERSSTUDYINFO_NULL;
import static com.sunlands.zlcx.usercenter.vo.CommonResultMessage.USERSTARGETRELATIONDO_NULL;

@Component
@Scope("prototype")
public class StatusContext<T extends ITypeStatus> {

    private T typeStatus;

    public void setTypeStatus(T t) {
        this.typeStatus = t;
    }

    public void doLearnChange(UsersStudyInfoVO usersStudyInfoVO, UsersTargetRelationDO usersTargetRelationDO) {
        if(AssertUtil.isEmpty(usersStudyInfoVO)){
            throw new CheckRunException(USERSSTUDYINFO_NULL.message);
        } else if (AssertUtil.isEmpty(usersTargetRelationDO)) {
            throw new CheckRunException(USERSTARGETRELATIONDO_NULL.message);
        }
        typeStatus.handle(usersStudyInfoVO, usersTargetRelationDO);
    }
}
